package com.mikao.service.impl;

import com.mikao.dao.ServiceDao;
import com.mikao.dto.vo.BaseResult;
import com.mikao.dto.vo.ServiceDto;
import com.mikao.service.ServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kenny
 */

@Slf4j
@Service
public class ServiceServiceImpl implements ServiceService {

    private ServiceDao serviceDao;

    public ServiceServiceImpl(ServiceDao serviceDao) {
        this.serviceDao = serviceDao;
    }

    @Override
    public BaseResult<List<ServiceDto>> list() {
        List<ServiceDto> dtos = new ArrayList<>();
        ServiceDto dto;

        List<com.mikao.entity.Service> list = serviceDao.findAll();
        for (com.mikao.entity.Service service : list) {
            dto = new ServiceDto();
            BeanUtils.copyProperties(service, dto);
            dtos.add(dto);
        }
        return new BaseResult<>(dtos);
    }
}
